<template>
	<div id="login" class="flex-center flex-column page" v-if="show">
		<div class="title">欢迎登录-巡检端</div>
		<div class="f1">北碚区污水管道抢险平台</div>
		<div>
			<van-form>
				<div class="flex-center flex-column">
					<input class="inputClass" name="账号" v-model="form.username" placeholder="请输入账号" />
					<input class="inputClass" name="密码" v-model="form.password" type="password" placeholder="请输入密码" />

					<div style="margin: 16px">
						<van-button class="submit" round block type="info" native-type="submit" @click="login_index">登录</van-button>
					</div>
				</div>
			</van-form>
		</div>
	</div>
</template>
<script>
import { mapState } from 'vuex';
import bottomText from '@/components/global/bottomText';
import Qs from 'qs'; //引入qs  时axios的自带模块
var codeSetTime;
export default {
	name: 'app',
	components: {
		bottomText,
	},
	data() {
		return {
			dataList: {},
			value1: '', //PC mobile
			username: '',
			password: '',
			loading: false,
			codeTime: 60,
			homePath: '/home',
			show: true,
			form: {
				username: '',
				password: '',
				phone: '',
				code: '',
				role: 'C', //角色（C：企业；B：合作商；L：法律机构）
			},
		};
	},

	created() {
		// var role = this.$route.query.role; //带角色参数跳登录页
		// if (role) {
		// 	this.form.role = role;
		// 	if (role == 'B') {
		// 		this.homePath = '/FinancialService/index';
		// 	} else if (role == 'L') {
		// 		this.homePath =
		// 			'/NonPublicOwnershipRights/legalService_consult';
		// 	}
		// }
		// var currentPath = this.$route.query.currentPath; //各个页面带路径跳登录页 登录后回跳
		// if (currentPath) {
		// 	this.homePath = currentPath;
		// }
		// if (process.env.NODE_ENV == 'production') {
		// 	this.show = false;
		// 	//浙里办版本(生产环境) 直接免登
		// 	//跳转浙里办登录 实现单点登录
		// 	// window.location.href =
		// 	// 	'https://api.xiangcun0577.com/ato/zjzwfw/sso/login?mobile=true'; //移动到App.vue
		// 	// this.getUserForDandian(); //根据能不能获取到用户类型 来判断是否是浙里办打开（第一次登录的用户获取不到用户信息 暂时废弃）
		// } else {
		// 	//普通版本 不单点登录
		// }
	},
	// http引用

	mounted() {
		this.jsonHttpTest();
	},
	methods: {
		login_index() {
			var params = {
				username: this.form.username,
				password: this.form.password,
				// code: this.form.code,
				// role: this.form.role,
			};
			this.$myApi.login_index(params).then((res) => {
				if (res.code == 200) {
					this.$notify({ type: 'success', message: '登录成功' });
					this.$store.state.token = res.data;
					window.localStorage.setItem(
						'token',
						JSON.stringify(res.data)
					);
					window.localStorage.setItem('token', res.data);
					this.getInfo_index();
				} else {
				}
			});
		},
		getInfo_index() {
			var params = {};
			this.$myApi.getInfo_index(params).then((res) => {
				if (res.code == 200) {
					
					window.localStorage.setItem(
						'userList',
						JSON.stringify(res.data)
					);
					this.$store.state.userList = res.data;
					this.$store.state.token = res.data;
					this.$router.push(this.homePath);
				} else {
				}
			});
		},
	},
};
</script>
<style lang="less" scoped>
#login {
	.title {
		font-size: 0.54rem;
		color: #142742;
		font-weight: bold;
		font-family: FZDaHei-B02S;
		margin-bottom: 0.11rem;
	}
	.f1 {
		font-weight: bold;
		font-size: 0.28rem;
		margin-bottom: 1rem;
		font-size: 0.5rem;
		color: #142742;
		font-weight: bold;
		font-family: FZDaHei-B02S;
		margin-bottom: 1.39rem;
	}
	.inputClass {
		background: #f6f6f6;
		border-radius: 1rem;
		border: none;
		padding: 0.36rem 0.48rem;
		width: 5.42rem;
		margin-bottom: 0.63rem;
		font-size: 0.4rem;
	}
	.inputWrap {
		position: relative;
		.code {
			position: absolute;
			right: 10%;
			top: 24%;
			font-size: 0.28rem;
		}
	}
	.submit {
		width: 5.42rem;
		height: 1rem;
		background: #0661de;
		border-radius: 1rem;
	}
}
</style>